perm filename DUMPAS.PAS[PAS,SYS] blob sn#472157 filedate 1979-09-13 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	(*$e+,t-,d-*)
C00009 ENDMK
C⊗;
(*$e+,t-,d-*)
PROGRAM dumper, dpcnts, inittiming, timeit;
    (**********************************************************************
     *
     *  (C) COPYRIGHT  1979
     *          BOARD OF TRUSTEES
     *          LELAND STANFORD JUNIOR UNIVERSITY
     *              STANFORD, CA. 94305, U. S. A.
     *
     *      (C) COPYRIGHT 1979,
     *          ARMANDO R. RODRIGUEZ
     *              LOTS COMPUTER FACILITY
     *              STANFORD UNIVERSITY
     *              STANFORD, CA. 94305, U. S. A.
     *
     *      AUXILIARY ROUTINES FOR STATEMENT COUNTS (PROFILE)
     *      AS IMPLEMENTED BY PHILIP WISOFF, FEB-79
     *	    modified by armando r. rodriguez, sep-79: support timing of 
     *		basic blocks (monitor) and procedures (profile)
     *
     *      DPCNTS:
     *              DUMPS TO A FILE OF INTEGER THE LINE/PAGE MARKERS AND
     *              THE COUNTS FOR EACH BASIC BLOCK.
     *
     *********************************************************************)

TYPE
	linerange = 0..777777B;
	pagerange = 0..377777B;
	data = PACKED RECORD
			  line: linerange;
			  timerflag: boolean;
			  page: pagerange;
			  count: integer;
		      END;
    dfiletype = FILE OF data;
    packed9 = PACKED ARRAY [1..9] OF char;
    pointer = ↑integer;
    hack = record
	case boolean of
	   true: (val: integer);
	   false: (ptr: pointer);
	   end;

VAR
    dumpfile : dfiletype;
   globtime,
   thistime, lasttime: integer;
   lastaddress: pointer;
   reg1: hack;

PROCEDURE dpcnts (filename : packed9;startofcounts,endofcounts : integer);

    TYPE
	pointer = RECORD
		      CASE boolean OF
			   true : (location : ↑data);
			   false : (incloc : linerange);
		  END;
    VAR
	dataptr : pointer;
	countdata : data;

    BEGIN (*DPCNTS*)
    rewrite(dumpfile,filename);             (*OPEN THE FILE*)
    WITH dataptr DO BEGIN
	dataptr.incloc := startofcounts;
	WHILE dataptr.incloc <= endofcounts DO  (*FOR EACH COUNT MARKER*)
	    BEGIN
	    %3
	    with location↑ do			(*at sail, we get microseconds*)
		if timerflag then
		count := (count + 5) div 10;
		\
		dumpfile↑ := location↑;
		put(dumpfile);
	    dataptr.incloc := dataptr.incloc + 2;   (*AND GO TO THE NEXT*)
	    END;
	END;
    reset(dumpfile,filename);                       (*CLOSE THE FILE*)
    %3 message('to produce the profile listing, .r pcref');	\
    END;

(*these are the procedures that will get called by the extra code generated     *)
(*by the compiler for timing:  it would be great if you can implement them in   *)
(*macro. i will pass THISADDRESS (for TIMEIT) in register 1.                    *)

function jobmic: integer;
   begin
   jobmic := clock * 1000;
   end;

PROCEDURE inittiming;
   (*clears the pointer, and starts the reference time*)
   (*  to be called at the beginning of execution *)

   BEGIN (*inittiming*)
   lastaddress := NIL;
   lasttime := jobmic;
   globtime := lasttime;
   reg1.val := 1;
   END (*inittiming*);

PROCEDURE timeit;
   (* saves the time accumulated and resets the reference time and address*)
   (* to be called at each timing breakpoint. the last call will occur at *)
   (* the end of the program, and will pass nil as a parameter. *)
    var
	thisaddress: hack;

   BEGIN (*timeit*)
   thisaddress.val := reg1.ptr↑;
   if lastaddress <> thisaddress.ptr then
	begin
   thistime := jobmic;
   IF lastaddress <> NIL THEN
      lastaddress↑ := lastaddress↑ + thistime - lasttime;
   lastaddress := thisaddress.ptr;
   lasttime := thistime;
	end;
   END (*timeit*);

procedure lasttimeproc;
    begin
    lastaddress↑ := thistime - globtime;		(*calculate the global cpu time*)
    end;

BEGIN
END.